﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace B.S.Sell.Infacet.Migrations
{
    public partial class w1 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "ProductModel",
                columns: table => new
                {
                    ProductId = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    ProductName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ManufacturerCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    InternalCode = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    UnitId = table.Column<int>(type: "int", nullable: false),
                    Category = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    UpperLimit = table.Column<double>(type: "float", nullable: false),
                    LowerLimit = table.Column<double>(type: "float", nullable: false),
                    Specification = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    WHouseId = table.Column<int>(type: "int", nullable: false),
                    WHouseTypeId = table.Column<int>(type: "int", nullable: false),
                    Description = table.Column<string>(type: "nvarchar(max)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ProductModel", x => x.ProductId);
                });

            migrationBuilder.CreateTable(
                name: "SellModel",
                columns: table => new
                {
                    PurchaseOrderId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    PurchaseOrderNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    BillType = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    AssociatedorderNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    SupplierName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    CustomerName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ContactPerson = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Phone = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ReceiveDate = table.Column<DateTime>(type: "datetime2", nullable: true),
                    Remark = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Maker = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    MakeTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SellModel", x => x.PurchaseOrderId);
                });

            migrationBuilder.CreateTable(
                name: "PurchaseOrderProduct",
                columns: table => new
                {
                    PurchaseOrderProductId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    PurchaseOrderId = table.Column<int>(type: "int", nullable: true),
                    SellModelPurchaseOrderId = table.Column<int>(type: "int", nullable: true),
                    ProductId = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ProductModelProductId = table.Column<string>(type: "nvarchar(450)", nullable: true),
                    Quantity = table.Column<decimal>(type: "decimal(18,2)", nullable: true),
                    UnitPrice = table.Column<decimal>(type: "decimal(18,2)", nullable: true),
                    TotalPrice = table.Column<decimal>(type: "decimal(18,2)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PurchaseOrderProduct", x => x.PurchaseOrderProductId);
                    table.ForeignKey(
                        name: "FK_PurchaseOrderProduct_ProductModel_ProductModelProductId",
                        column: x => x.ProductModelProductId,
                        principalTable: "ProductModel",
                        principalColumn: "ProductId");
                    table.ForeignKey(
                        name: "FK_PurchaseOrderProduct_SellModel_SellModelPurchaseOrderId",
                        column: x => x.SellModelPurchaseOrderId,
                        principalTable: "SellModel",
                        principalColumn: "PurchaseOrderId");
                });

            migrationBuilder.CreateIndex(
                name: "IX_PurchaseOrderProduct_ProductModelProductId",
                table: "PurchaseOrderProduct",
                column: "ProductModelProductId");

            migrationBuilder.CreateIndex(
                name: "IX_PurchaseOrderProduct_SellModelPurchaseOrderId",
                table: "PurchaseOrderProduct",
                column: "SellModelPurchaseOrderId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "PurchaseOrderProduct");

            migrationBuilder.DropTable(
                name: "ProductModel");

            migrationBuilder.DropTable(
                name: "SellModel");
        }
    }
}
